package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.RewardPunishmentReport;
import com.amsp.oa.oademo.service.RewardPunishmentReportService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/reward-punishment-report")
@Api(tags = "奖惩提报单接口")
public class RewardPunishmentReportController {

    @Autowired
    private RewardPunishmentReportService rewardPunishmentReportService;

    @PostMapping("/save")
    @ApiOperation("保存奖惩提报单")
    public ResponseEntity<RewardPunishmentReport> save(@RequestBody RewardPunishmentReport rewardPunishmentReport) {
        if (rewardPunishmentReport.getId() != null) {
            rewardPunishmentReportService.updateById(rewardPunishmentReport);
        } else {
            rewardPunishmentReportService.save(rewardPunishmentReport);
        }
        return ResponseEntity.ok(rewardPunishmentReport);
    }

    @PostMapping("/batch-save")
    @ApiOperation("批量保存奖惩提报单")
    public ResponseEntity<List<RewardPunishmentReport>> batchSave(
            @RequestBody List<RewardPunishmentReport> rewardPunishmentReports) {
        rewardPunishmentReportService.saveOrUpdateBatch(rewardPunishmentReports);
        return ResponseEntity.ok(rewardPunishmentReports);
    }

    @GetMapping("/list")
    @ApiOperation("获取奖惩提报单列表")
    public ResponseEntity<IPage<RewardPunishmentReport>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size) {
        return ResponseEntity.ok(rewardPunishmentReportService.getPage(current, size));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取奖惩提报单详情")
    public ResponseEntity<RewardPunishmentReport> getById(@PathVariable Long id) {
        return ResponseEntity.ok(rewardPunishmentReportService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除奖惩提报单")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        rewardPunishmentReportService.removeById(id);
        return ResponseEntity.ok().build();
    }
}